package com.shijiwei.lifthelper.utils;

import org.xutils.DbManager;
import org.xutils.x;

/**
 * Created by sjw on 2015/12/8.
 */
public class DbUtils {

    private static DbManager db = null;
    private static DbManager.DaoConfig config;

    public static DbManager getDb(){
        if (db == null){
            config = new DbManager.DaoConfig();
            config.setDbDir(FileUtils.getDbFile());
            config.setDbName(AppConfig.DB_NAME);
            config.setAllowTransaction(true);
            config.setDbVersion(AppConfig.DB_VERSION);
            config.setDbUpgradeListener(new DbManager.DbUpgradeListener() {
                @Override
                public void onUpgrade(DbManager db, int oldVersion, int newVersion) {
                    if (newVersion > oldVersion) {

                    }
                }
            });

            db = x.getDb(config);
        }
        return db;
    }
}
